package com.nongtai.handler;

import com.nongtai.enums.ReturnCodeEnum;
import com.nongtai.exception.BaseException;
import com.nongtai.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 * @author yza
 * @version 1.0
 * @date 2024/6/18 10:40
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 处理所有自定义业务异常
     * @param e
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public Result handelServiceException(BaseException e){
        return Result.error(e.getMessage(),ReturnCodeEnum.BUSINESS_ERROR.getCode());
    }
}
